#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int findMaxLength(vector<int>&& nums) {
    int n = nums.size();

    int sum = 0;
    int ret = 0;
    unordered_map<int, int> hash(n);
    hash[0] = -1;

    for (int i = 0; i < n; ++i)
    {
        sum += nums[i] == 0 ? -1 : 1;
        if (hash.count(sum)) 
            ret = max(ret, i - hash[sum]);
        else    
            hash[sum] = i;
    }

    return ret;
}

int main()
{
    findMaxLength({ 0,1,0 });
	return 0;
}